import requests
from concurrent.futures import ThreadPoolExecutor

# 接口 URL 模板
#url_template = "http://106.52.201.90:7001/api/ccSmart/fillMusicTopicTag/invoke?limit=200&beginId={}"
#url_template = "http://106.55.8.90:7001/api/ccSmart/fillMusicTopicTag/invoke?limit=200&beginId={}"
url_template = "http://106.53.146.53:7001/api/ccSmart/fillMusicTopicTag/invoke?limit=200&beginId={}"

# 不同的 spanId 列表
span_ids = [
    5543533, 5556740, 5563583, 5570348, 5570562, 5577023, 5583608, 5590574, 5590796, 5604088, 5616141, 5628936,
     5629197, 5636016, 5642798, 5649742, 5663058, 5663140]



    # 请求头
headers = {
    'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
}

# 定义请求函数
def call_api(span_id):
    url = url_template.format(span_id)
    try:
        requests.get(url, headers=headers, timeout=1)  # 设置 timeout 避免阻塞
        print(f"Request sent with spanId={span_id}")
    except Exception as e:
        print(f"Error with spanId={span_id}: {e}")

# 使用线程池异步调用
with ThreadPoolExecutor(max_workers=10) as executor:  # 最多 10 个并发
    executor.map(call_api, span_ids)

print("All requests sent asynchronously!")